package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.LogisticsService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.LogisticsAddVO;
import com.junzhiit.nengji.cms.web.vo.LogisticsEditVO;
import com.junzhiit.nengji.cms.web.vo.LogisticsVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/logistics")
public class LogisticsController extends BaseController {

	@Autowired
	private LogisticsService logisticsService;

	@ApiOperation(value = "获取所有物流列表")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp, LogisticsVO logisticsVO) {
		return logisticsService.findAll(dtp, logisticsVO);
	}

	@ApiOperation(value = "根据ID查询物流")
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResultVO findById(@PathVariable String id) {
		AssertUtil.notBlank(id, "id is required.");
		return logisticsService.findById(id);
	}

	@ApiOperation(value = "创建物流")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(LogisticsAddVO logisticsAddVO) {
		AssertUtil.notBlank(logisticsAddVO.getName(), "name is required.");
		AssertUtil.notBlank(logisticsAddVO.getCode(), "code is required.");
		AssertUtil.notBlank(logisticsAddVO.getTel(), "tel is required.");
		AssertUtil.notBlank(logisticsAddVO.getLetter(), "letter is required.");
		return logisticsService.add(logisticsAddVO);
	}

	@ApiOperation(value = "修改物流")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO update(LogisticsEditVO logisticsEditVO) {
		AssertUtil.notBlank(logisticsEditVO.getName(), "name is required.");
		AssertUtil.notBlank(logisticsEditVO.getCode(), "code is required.");
		AssertUtil.notBlank(logisticsEditVO.getTel(), "tel is required.");
		AssertUtil.notBlank(logisticsEditVO.getLetter(), "letter is required.");
		return logisticsService.edit(logisticsEditVO);
	}

	@ApiOperation(value = "删除物流")
	@RequestMapping(value = "/del", method = RequestMethod.PUT)
	public ResultVO delete(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return logisticsService.delete(id);
	}

	@ApiOperation(value = "置顶")
	@RequestMapping(value = "/toTop", method = RequestMethod.PUT)
	public ResultVO toTop(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return logisticsService.toTop(id);
	}
	
	@ApiOperation(value = "查询物流下拉框")
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public ResultVO getList() {
		return logisticsService.getList();
	}
	
	@ApiOperation(value = "物流跟踪")
	@RequestMapping(value = "/trace", method = RequestMethod.GET)
	public ResultVO logisticsTrace(String logisticsNumber,String logisticsCode) {
		AssertUtil.notBlank(logisticsNumber, "logisticsNumber is required.");
		return logisticsService.logisticsTrace(logisticsNumber,logisticsCode);
	}
}
